﻿<div [@routerTransition]>
    <div class="m-subheader ">
        <div class="d-flex align-items-center">
            <div class="mr-auto col-xs-6">
                <h3 class="m-subheader__title m-subheader__title--separator">
                    <span>{{l("ColumnInfo")}}</span>
                </h3>
            </div>
            <div class="col-sm-6 text-right">
                <audit-log serviceName="ColumnInfoAppService" objectName="Magicodes.Admin.Core.Custom.Contents.ColumnInfo"></audit-log>
                <button type="button" class="btn btn-success" (click)="exportToExcel()">
                    <i class="fa fa-file-excel-o"></i> {{l("ExportToExcel")}}
                </button>
                <button class="btn btn-primary blue" (click)="createColumnInfo()">
                    <i class="fa fa-plus"></i>{{l("Create")}}
                </button>
                <button type="button" class="btn btn-metal" (click)="getColumnInfos()">
                    <i class="fa fa-refresh"></i> {{l("Refresh")}}
                </button>
                <button type="button" class="btn default" (click)="getRecycleData()">
                    <i class="fa fa-recycle"></i> {{model.isOnlyGetRecycleData?l('Close'):l('RecycleBin')}}
                </button>
                <button type="button" class="btn default" (click)="showOrdinaryTable()">
                    <i class="fa fa-table"></i> {{isShowTreeTable?l('OrdinaryTable'):l('TreeTable')}}
                </button>
            </div>
        </div>
    </div>
    <div class="m-content">
        <div class="m-portlet m-portlet--mobile">
            <div class="m-portlet__body">
                <div class="m-form m-form--label-align-right">
                    <form (submit)="getColumnInfos()" autocomplete="off">
                        <div class="form-body">
                            <div class="row m--margin-bottom-10">
                                <label>{{l("Filter")}}</label>
                                <div class="input-group">
                                    <input [(ngModel)]="model.filterText" name="Filter" class="form-control" placeholder="{{l('SearchWithThreeDot')}}" type="text">
                                </div>
                            </div>
                        </div>
                        <div *ngIf="advancedFiltersAreShown" class="row">
                            <div class="col-xl-6">
                                <div class="m-checkbox-list">
                                    <label class="m-checkbox">
                                        <input type="checkbox" [(ngModel)]="model.creationDateRangeActive" id="model_CreateDateRange" name="CreateDateRange" value="true"> {{l('CreateDateRange')}}
                                        <span></span>
                                    </label>
                                </div>
                                <date-range-picker name="CreateDateRange" [isDisabled]="!model.createDateRange" [(startDate)]="model.creationDateStart" [(endDate)]="model.creationDateEnd"
                                    [allowFutureDate]="true">
                                </date-range-picker>
                            </div>
                            <div class="col-xl-6">
                                <div class="m-checkbox-list">
                                    <label class="m-checkbox">
                                        <input type="checkbox" [(ngModel)]="model.subscriptionEndDateRangeActive" id="model_updateDateRange" name="UpdateDateRange"
                                            value="true"> {{l('UpdateDateRange')}}
                                        <span></span>
                                    </label>
                                </div>
                                <date-range-picker name="UpdateDateRange" [isDisabled]="!model.updateDateRange" [(startDate)]="model.subscriptionEndDateStart"
                                    [(endDate)]="model.subscriptionEndDateEnd" [allowFutureDate]="false">
                                </date-range-picker>
                            </div>
                            <div class="col-md-6">
                                <label for="SubmenuToggle">{{l("IsActive")}}</label>
                                <select id="IsActive" name="IsActive" class="form-control" [(ngModel)]="model.isActive">
                                    <option value="all">{{l("All")}}</option>
                                    <option value="yes">{{l("Yes")}}</option>
                                    <option value="no">{{l("No")}}</option>
                                </select>
                            </div>
                            <div class="col-md-6">
                                <label for="SubmenuToggle">{{l("IsNeedAuthorizeAccess")}}</label>
                                <select id="IsNeedAuthorizeAccess" name="IsNeedAuthorizeAccess" class="form-control" [(ngModel)]="model.isNeedAuthorizeAccess">
                                    <option value="all">{{l("All")}}</option>
                                    <option value="yes">{{l("Yes")}}</option>
                                    <option value="no">{{l("No")}}</option>
                                </select>
                            </div>
                        </div>
                        <div class="row m--margin-bottom-10">
                            <div class="col-sm-6">
                                <span class="clickable-item text-muted" *ngIf="!advancedFiltersAreShown" (click)="advancedFiltersAreShown=!advancedFiltersAreShown">
                                    <i class="fa fa-angle-down"></i> {{l("ShowAdvancedFilters")}}
                                </span>
                                <span class="clickable-item text-muted" *ngIf="advancedFiltersAreShown" (click)="advancedFiltersAreShown=!advancedFiltersAreShown">
                                    <i class="fa fa-angle-up"></i> {{l("HideAdvancedFilters")}}
                                </span>
                            </div>
                        </div>
                    </form>
                </div>

                <!--<Primeng-TreeTable-Start>-->
                <div class="row align-items-center" *ngIf="isShowTreeTable">
                    <div class="primeng-datatable-container">
                        <p-treeTable [value]="list" [paginator]="false" [lazy]="false" [loading]="loading" (onNodeExpand)="onNodeExpand($event)">
                            <ng-template pTemplate="header" let-columns>
                                <tr>
                                    <th style="width:110px"></th>
                                    <th style="width:130px">{{l('Actions')}}</th>
                                    <th [ttSortableColumn]="title" style="width:200px">{{l('Title')}}
                                        <p-treeTableSortIcon field="title"></p-treeTableSortIcon>
                                    </th>
                                    <th [ttSortableColumn]="isActive" style="width:200px">{{l('IsActive')}}
                                        <p-treeTableSortIcon field="isActive"></p-treeTableSortIcon>
                                    </th>
                                    <th [ttSortableColumn]="isNeedAuthorizeAccess" style="width:200px">{{l('IsNeedAuthorizeAccess')}}
                                        <p-treeTableSortIcon field="isNeedAuthorizeAccess"></p-treeTableSortIcon>
                                    </th>
                                    <th [ttSortableColumn]="iconCls" style="width:200px">{{l('IconCls')}}
                                        <p-treeTableSortIcon field="iconCls"></p-treeTableSortIcon>
                                    </th>
                                    <th style="width:600px">{{l('PictureManage')}}</th>
                                    <th [ttSortableColumn]="url" style="width:200px">{{l('Url')}}
                                        <p-treeTableSortIcon field="url"></p-treeTableSortIcon>
                                    </th>
                                    <th [ttSortableColumn]="creationTime" style="width:200px">{{l('CreationTime')}}
                                        <p-treeTableSortIcon field="creationTime"></p-treeTableSortIcon>
                                    </th>
                                </tr>
                            </ng-template>
                            <ng-template pTemplate="body" let-rowNode let-rowData="rowData" let-columns="columns">
                                <tr>
                                    <td style="width: 110px">
                                        <p-treeTableToggler [rowNode]="rowNode"></p-treeTableToggler>
                                    </td>
                                    <td style="width: 130px">
                                        <div class="btn-group dropdown" normalizePosition>
                                            <button class="dropdown-toggle btn btn-sm btn-primary" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                                                <i class="fa fa-cog"></i>
                                                <span class="caret"></span> {{l("Actions")}}
                                            </button>
                                            <ul class="dropdown-menu" *ngIf="!rowData.isDeleted">
                                                <li>
                                                    <a (click)="editDistrictInfo(rowData.id)">{{l('Edit')}}</a>
                                                </li>
                                                <li>
                                                    <a (click)="deleteDistrictInfo(rowData.id)">{{l('Delete')}}</a>
                                                </li>
                                                <li>
                                                    <a (click)="fileUploadModal.show(rowData.id)">{{l('PictureManage')}}</a>
                                                </li>
                                            </ul>
                                            <ul class="dropdown-menu" *ngIf="rowData.isDeleted">
                                                <li>
                                                    <a (click)="restore(rowData.id)">{{l('Restore')}}</a>
                                                </li>
                                            </ul>
                                        </div>
                                    </td>
                                    <td style="width:200px">{{rowData.title}}</td>
                                    <td style="width:200px">
                                        <p-inputSwitch (onChange)="handleIsActiveSwitch($event,rowData.id)" [(ngModel)]="rowData.isActive"></p-inputSwitch>
                                    </td>
                                    <td style="width:200px">
                                        <p-inputSwitch (onChange)="handleIsNeedAuthorizeAccessSwitch($event,rowData.id)" [(ngModel)]="rowData.isNeedAuthorizeAccess"></p-inputSwitch>
                                    </td>
                                    <td style="width:200px">{{rowData.iconCls}}</td>
                                    <td style="width:600px">
                                        <object-imageList objectTypeName="ColumnInfo" [(objectId)]="rowData.id"></object-imageList>
                                    </td>
                                    <td style="width:200px">{{rowData.url}}</td>
                                    <td style="width:200px">
                                        {{ rowData.creationTime ? (rowData.creationTime | momentFormat:'L LT') : '-'}}
                                    </td>
                                </tr>
                            </ng-template>
                        </p-treeTable>
                    </div>
                </div>
                <!--<Primeng-TreeTable-End>-->

                <div class="row align-items-center" *ngIf="!isShowTreeTable">
                    <!--<Primeng-Datatable-Start>-->
                    <div class="primeng-datatable-container" [busyIf]="primengTableHelper.isLoading">
                        <p-table #dataTable (onLazyLoad)="getColumnInfos($event)" [value]="primengTableHelper.records" rows="{{primengTableHelper.defaultRecordsCountPerPage}}"
                            [paginator]="false" [lazy]="true" [responsive]="primengTableHelper.isResponsive" [scrollable]="true"
                            [style]="{width:'100%'}" (onRowReorder)="getReorder($event)">
                            <ng-template pTemplate="header">
                                <tr>
                                    <th style="width:30px"></th>
                                    <th style="width:130px">{{l('Actions')}}</th>
                                    <th pSortableColumn="title" style="width:200px">{{l('Title')}}
                                        <p-sortIcon field="title"></p-sortIcon>
                                    </th>
                                    <th pSortableColumn="isActive" style="width:200px">{{l('IsActive')}}
                                        <p-sortIcon field="isActive"></p-sortIcon>
                                    </th>
                                    <th pSortableColumn="isNeedAuthorizeAccess" style="width:200px">{{l('IsNeedAuthorizeAccess')}}
                                        <p-sortIcon field="isNeedAuthorizeAccess"></p-sortIcon>
                                    </th>
                                    <th pSortableColumn="iconCls" style="width:200px">{{l('IconCls')}}
                                        <p-sortIcon field="iconCls"></p-sortIcon>
                                    </th>
                                    <th style="width:600px">{{l('PictureManage')}}</th>
                                    <th pSortableColumn="url" style="width:200px">{{l('Url')}}
                                        <p-sortIcon field="url"></p-sortIcon>
                                    </th>
                                    <th pSortableColumn="creationTime" style="width:200px">{{l('CreationTime')}}
                                        <p-sortIcon field="creationTime"></p-sortIcon>
                                    </th>
                                </tr>
                            </ng-template>

                            <ng-template pTemplate="body" let-record="$implicit" let-index="rowIndex">
                                <tr [pReorderableRow]="index">
                                    <td style="width:30px">
                                        <i class="fa fa-arrows" title="{{l('DragAndDropSortTip')}}" pReorderableRowHandle></i>
                                    </td>
                                    <td style="width: 130px">
                                        <div class="btn-group dropdown" normalizePosition>
                                            <button class="dropdown-toggle btn btn-sm btn-primary" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                                                <i class="fa fa-cog"></i>
                                                <span class="caret"></span> {{l("Actions")}}
                                            </button>
                                            <ul class="dropdown-menu" *ngIf="!record.isDeleted">
                                                <li>
                                                    <a (click)="editColumnInfo(record.id)">{{l('Edit')}}</a>
                                                </li>
                                                <li>
                                                    <a (click)="deleteColumnInfo(record.id)">{{l('Delete')}}</a>
                                                </li>
                                                <li>
                                                    <a (click)="fileUploadModal.show(record.id)">{{l('PictureManage')}}</a>
                                                </li>
                                            </ul>
                                            <ul class="dropdown-menu" *ngIf="record.isDeleted">
                                                <li>
                                                    <a (click)="restore(record.id)">{{l('Restore')}}</a>
                                                </li>
                                            </ul>
                                        </div>
                                    </td>
                                    <td style="width:200px">{{record.title}}</td>
                                    <td style="width:200px">
                                        <p-inputSwitch (onChange)="handleIsActiveSwitch($event,record.id)" name="IsActive" [(ngModel)]="record.isActive"></p-inputSwitch>
                                    </td>
                                    <td style="width:200px">
                                        <p-inputSwitch (onChange)="handleIsNeedAuthorizeAccessSwitch($event,record.id)" name="IsActive" [(ngModel)]="record.isNeedAuthorizeAccess"></p-inputSwitch>
                                    </td>
                                    <td style="width:200px">{{record.iconCls}}</td>
                                    <td style="width:600px">
                                        <object-imageList objectTypeName="ColumnInfo" [(objectId)]="record.id"></object-imageList>
                                    </td>
                                    <td style="width:200px">{{record.url}}</td>
                                    <td style="width:200px">
                                        {{ record.creationTime ? (record.creationTime | momentFormat:'L LT') : '-'}}
                                    </td>
                                </tr>
                            </ng-template>
                        </p-table>

                        <div class="primeng-paging-container">
                            <p-paginator rows="{{primengTableHelper.defaultRecordsCountPerPage}}" #paginator (onPageChange)="getColumnInfos($event)"
                                [totalRecords]="primengTableHelper.totalRecordsCount" [rowsPerPageOptions]="primengTableHelper.predefinedRecordsCountPerPage">
                            </p-paginator>
                            <span class="total-records-count">
                                {{l('TotalRecordsCount', primengTableHelper.totalRecordsCount)}}
                            </span>
                        </div>
                    </div>
                    <!--<Primeng-TurboTable-End>-->
                </div>





            </div>
        </div>
    </div>

    <createOrEditColumnInfoModal #createOrEditColumnInfoModal (modalSave)="getColumnInfos()"></createOrEditColumnInfoModal>
    <fileUploadModal #fileUploadModal objectTypeName="ColumnInfo"></fileUploadModal>
</div>